package com.los;

import java.util.Optional;

/**
 * @program: java8
 * @description: optional容器
 * @author: Yujuan
 * @create: 2018-06-14 16:54
 **/
public class OptionalUsage {
    public static void main(String[] args) {
        Optional<Insurance> insurance=Optional.of(new Insurance());
        System.out.println(insurance.get());
        System.out.println(Optional.ofNullable(new Insurance().getName()).orElse("123"));
//        Optional<Insurance> optionalInsurance=Optional.empty();
//        optionalInsurance.get();

       Optional<Insurance> optional=Optional.of(new Insurance());
//       optional=Optional.ofNullable(new Insurance());
//       optional.orElseGet(Insurance::new);
//       optional.orElse(new Insurance());
//       optional.orElseThrow(RuntimeException::new);

        System.out.println(optional.filter(i->i.getName()!=null).get());

    }
}
